package org.gd.spring.jdbc;

import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;
import javax.sql.DataSource;

public class JdbcCustomerDAO implements CustomerDAO {

    //private DataSource dataSource;
    private JdbcTemplate jdbcTemplate;

    private String sqlInsert;
    private String sqlFindAllById;
    private String sqlFindAll;

    public JdbcCustomerDAO(DataSource dataSource) {
        //this.dataSource = dataSource;
        jdbcTemplate = new JdbcTemplate(dataSource);
    }

    public void insert(Customer customer){
        jdbcTemplate.update(getSqlInsert(), customer.getName(), customer.getAge());
    }

    public List<Customer> findByCustomerId(int custId) {
        return jdbcTemplate.query(getSqlFindAllById(), new Object[]{custId}, new Customer());
    }

    public List<Customer> getAllCustomers() {
        return jdbcTemplate.query(getSqlFindAll(), new Customer());
    }

    @SuppressWarnings("unused")
    public String getSqlInsert() {
        return sqlInsert;
    }

    @SuppressWarnings("unused")
    public void setSqlInsert(String sqlInsert) {
        this.sqlInsert = sqlInsert;
    }

    @SuppressWarnings("unused")
    public String getSqlFindAllById() {
        return sqlFindAllById;
    }

    @SuppressWarnings("unused")
    public void setSqlFindAllById(String sqlFindAllById) {
        this.sqlFindAllById = sqlFindAllById;
    }

    @SuppressWarnings("unused")
    public String getSqlFindAll() {
        return sqlFindAll;
    }

    @SuppressWarnings("unused")
    public void setSqlFindAll(String sqlFindAll) {
        this.sqlFindAll = sqlFindAll;
    }
}
